#! /usr/bin/env python
# -*- coding: utf-8 -*-

# Copyright (c) Huoty, All rights reserved
# Author: Huoty <sudohuoty@gmail.com>
# CreateTime: 2018-08-12 17:11:38

import sys
import pika

connection = pika.BlockingConnection(pika.ConnectionParameters(
        host='localhost'))
channel = connection.channel()

# 声明 headers 类型的 Exchange
channel.exchange_declare(exchange='headers_logs', exchange_type='headers')

severity = sys.argv[1] if len(sys.argv) > 1 else 'warning'
message = ' '.join(sys.argv[2:]) or 'Hello World!'
headers = {severity: severity}
channel.basic_publish(
    exchange='headers_logs',
    routing_key='',
    body=message,
    properties=pika.BasicProperties(headers=headers)
)

print ' [x] Send {0} with headers: {1}'.format(message, headers)
connection.close()
